/*! lzf */

var message = {
    initMessage: function (s) {
        var a, e, t;
        if (s = $(s).parent(), "1" != $(s).attr("data-posted") && (a = s, e = $(a).data("cache"), $.post(base.site_url() + "client/memMng/memSysMsg/getSysMsgDetail", {data: JSON.stringify(e)}, function (s) {
            0 == s.code && $(a).find("dd").html(s.data)
        }, "json")), $(s).hasClass("read")) {
            var n = $("#left_nav .message"), i = n.text();
            --i <= 0 ? $("#left_nav .message").remove() : n.html(i)
        }
        t = s, $(t).hasClass("show") ? ($(t).removeClass("show"), $(t).find("dd").addClass("none")) : ($(t).hasClass("read") && ($(t).addClass("readed"), $(t).removeClass("read")), $(t).addClass("show"), $(t).find("dd").removeClass("none")), $(s).attr("data-posted", "1")
    }
};
$(function () {
    var d = function (s, a) {
        if (s) {
            for (var e = "", t = 0, n = s.length; t < n; t++) {
                var i = s[t], d = "read";
                2 == i.sp_read_status && (d = "readed"), e += '<dl class="notify-item ' + d + '" data-cache=\'{"sys_pubmsg_id":"' + i.sys_pubmsg_id + '","sys_pubmsg_detail_id":"' + i.sys_pubmsg_detail_id + '","sp_read_status":"' + i.sp_read_status + '"}\'><dt onclick="message.initMessage(this)"><a class="notify-title-wrapper" href="javascript:void(0)"><span class="notify-status">' + i.sp_public_time.substring(0, 16) + '<i class="arrow"></i></span><span class="notify-title"><i class="dot">●</i>' + i.sp_title + '</span></a></dt><dd class="none"></dd></dl>'
            }
            a.html(e)
        }
    };
    $.post(base.site_url("client/memMng/memSysMsg/getSysMsg"), null, function (s) {
        if (0 === s.code) {
            var t = $("#msg_wrap"), a = s.data.rows, e = s.data.total, n = !1, i = $("#pagination");
            d(a, t), 10 < e ? i.pagination(e, {
                num_display_entries: 5,
                items_per_page: 10,
                prev_text: "上一页",
                next_text: "下一页",
                prev_show_always: !1,
                next_show_always: !1,
                callback: function (s, a) {
                    if (n) {
                        var e = {rows: 10, page: s};
                        $.post(base.site_url("client/memMng/memSysMsg/getSysMsg"), {data: JSON.stringify(e)}, function (s) {
                            0 === s.code && d(s.data.rows, t)
                        }, "json")
                    }
                    return !(n = !0)
                },
                current_page: 1,
                num_edge_entries: 0
            }) : 0 == a.length && t.html('<div class="col-info no-message"><span>暂无消息</span></div>')
        }
    }, "json"), $("#setAllMsgReaded").click(function () {
        $.post(base.site_url() + "client/memMng/memSysMsg/setAllMsgReaded", null, function (s) {
            0 === s.code ? window.location.reload() : base.alertMsg({text: s.message})
        }, "json")
    })
});